package models

import (
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

// 表的设计
// 在ORM里面__是有特殊含义的

func init() {

	//打开调试模式
	orm.Debug = true
	driverName := beego.AppConfig.String("driverName")
	user := beego.AppConfig.String("mysqluser")
	pwd := beego.AppConfig.String("mysqlpwd")
	host := beego.AppConfig.String("host")
	port := beego.AppConfig.String("port")
	dbname := beego.AppConfig.String("dbname")
	dbConn := user + ":" + pwd + "@tcp(" + host + ":" + port + ")/" + dbname + "?charset=utf8"
	//"root:root@tcp(127.0.0.1:3306)/goTest?charset=utf8"
	//ORM操作数据库
	//获取连接对象
	err := orm.RegisterDataBase("default", driverName, dbConn)
	if err != nil {
		fmt.Printf("连接数据库出错: %s", err)
		return
	}
	fmt.Println("连接数据库成功")
	//创建表
	orm.RegisterModel(new(Users), new(CustomerDevelopmentPlans), new(MarketingOpportunities), new(Customers), new(SalesOrders), new(Services), new(Contacts))

	//生成表
	//1.数据库别名
	//2.是否强制更新
	//3.创建表过程是否可见
	orm.RunSyncdb("default", false, true)
	//操作表

}
